home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / misc / amag / AM9407_2.lha / Locale-Library / listing3.c < prev    next >
C/C++ Source or Header  |  1994-06-28  |  2KB  |  72 lines

  1. /* Dieses Programm demonstriert die Benutzung der
  2.  * Funktion FormatDate()
  3.  * Verwendeter C-Compiler: SAS-C 6.5x
  4.  */
  5. #include <exec/types.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8. #include <proto/locale.h>
  9. #include <proto/utility.h>
  10. #include <stdio.h>
  11.  
  12. struct Library *LocaleBase=NULL;
  13. struct Locale *locale;
  14.  
  15. /* Diese Routine wird vom Betriebssystem angesprungen.
  16.  * Wir leiten den Aufruf schnurstracks an unsere eigene
  17.  * Routine weiter */
  18. ULONG __saveds __asm hookEntry(
  19.              register __a0 struct Hook *h, 
  20.              register __a2 void *obj, 
  21.              register __a1 void *msg)
  22. {
  23.   return((*h->h_SubEntry) (h,obj,msg));
  24. }
  25. /* Füllt die Hook-Struktur aus */
  26. void InitHook(struct Hook *hook,
  27.               ULONG (*func)(), 
  28.               void *data)
  29. {
  30.   if( hook ) {
  31.     hook->h_Entry = (ULONG (*)()) hookEntry;
  32.     hook->h_SubEntry = func;
  33.     hook->h_Data = data;
  34.   }
  35. }
  36. /* Erhält zeichenweise Informationen von FormatDate()
  37.  * der Locale-Library und gibt sie aus */
  38. ULONG __saveds __asm My_FormatDate(
  39.   register __a0 struct Hook *h, 
  40.   register __a2 void *obj, 
  41.   register __a1 void *msg) /* Hier steht das Zeichen */
  42. {
  43.   if( msg != 0 ) printf("%c",msg);
  44.   else           printf("\n");
  45.   return 1;
  46. }
  47. void main(ULONG argc, char **argv)
  48. {
  49.   struct Hook formdate;
  50.   if( argc ) {
  51.     /* Nur vom CLI zu starten */
  52.     LocaleBase=OpenLibrary("locale.library",38);
  53.     if( LocaleBase ) {
  54.       locale=OpenLocale(NULL);
  55.       if( locale ) {
  56.         struct DateStamp ds;
  57.         /* Die DateStamp-Struktur wird von FormatDate()
  58.          * benötigt */
  59.         DateStamp(&ds);
  60.         /* Einrichten unseres Hooks */
  61.         InitHook(&formdate, My_FormatDate, NULL);
  62.         /* Aufruf der Routine. Die Ausgabe erfolgt
  63.          * in Ma_FormatDate() */
  64.         FormatDate(locale,locale->loc_DateFormat,
  65.                    &ds,&formdate);
  66.         CloseLocale( locale );
  67.       }
  68.       CloseLibrary(LocaleBase);
  69.     } else printf("Locale-Library nicht vorhanden\n");
  70.   }
  71. }
  72.